package com.linked.goods.goodsbase.service.impl;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.linked.goods.goodsbase.bean.po.GoodsWarehousePO;
import com.linked.goods.goodsbase.mapper.IGoodsWareHouseMapper;
import com.linked.goods.goodsbase.service.IGoodsWareHouseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @author :dbq
 * @date : 2023/3/15 15:02
 * @description : desc
 */
@Service
@Slf4j
public class GoodsWareHouseServiceImpl implements IGoodsWareHouseService {

    private final IGoodsWareHouseMapper goodsWareHouseMapper;

    private final ObjectMapper mapper;

    @Autowired
    public GoodsWareHouseServiceImpl(IGoodsWareHouseMapper goodsWareHouseMapper, ObjectMapper mapper) {
        this.goodsWareHouseMapper = goodsWareHouseMapper;
        this.mapper = mapper;
    }

    @Override
    public int saveGoodsWareHouseList(List<GoodsWarehousePO> warehouseList) throws Exception {
        AtomicReference<Integer> count = new AtomicReference<>(0);
        warehouseList.stream().forEach(x -> count.updateAndGet(v -> v + goodsWareHouseMapper.insert(x)));
        return count.get();
    }
}
